/**
 * 测试规则: SwitchStatement
 * 来源: 从 Statement 拆分
 */

/* Es2025Parser.ts: switch (Expression) CaseBlock */

/**
 * 规则测试：SwitchStatement
 * 
 * 位置：Es2025Parser.ts Line 1300
 * 分类：statements
 * 编号：416
 * 
 * 规则语法：
 *   SwitchStatement:
 *     switch ( Expression ) CaseBlock
 *   CaseBlock:
 *     { CaseClause* DefaultClause? CaseClause* }
 * 
 * 测试目标：
 * - 验证各种case子句组合
 * - 验证default子句
 * - 覆盖fall-through和break场景
 * 
 * 创建时间：2025-11-01
 * 状态：✅ 已完善
 */

// ✅ 测试1：基本switch-case
let x = 1
switch (x) {
    case 1:
        console.log('one')
        break
    case 2:
        console.log('two')
        break
}

// ✅ 测试2：包含default
switch (x) {
    case 1:
        console.log('one')
        break
    default:
        console.log('other')
        break
}

// ✅ 测试3：多个case
let val = 3
switch (val) {
    case 1:
        console.log('one')
        break
    case 2:
        console.log('two')
        break
    case 3:
        console.log('three')
        break
    case 4:
        console.log('four')
        break
}

// ✅ 测试4：fall-through（无break）
let num = 1
switch (num) {
    case 1:
    case 2:
    case 3:
        console.log('1-3')
        break
    case 4:
    case 5:
        console.log('4-5')
        break
}

// ✅ 测试5：复杂表达式作为discriminant
let obj = { type: 'user' }
switch (obj.type) {
    case 'user':
        console.log('is user')
        break
    case 'admin':
        console.log('is admin')
        break
}

// ✅ 测试6：switch中的块语句
switch (x) {
    case 1: {
        const temp = x * 2
        console.log(temp)
        break
    }
    case 2: {
        console.log('case 2')
        break
    }
}

// ✅ 测试7：switch中的if-else
switch (x) {
    case 1:
        if (x > 0) {
            console.log('positive')
        }
        break
    case 2:
        console.log('two')
        break
}

// ✅ 测试8：switch中的for循环
switch (x) {
    case 1:
        for (let i = 0; i < 3; i++) {
            console.log(i)
        }
        break
    case 2:
        console.log('two')
        break
}

// ✅ 测试9：switch中的try-catch
switch (x) {
    case 1:
        try {
            console.log('try')
        } catch (e) {
            console.log('error')
        }
        break
}

// ✅ 测试10：嵌套switch
switch (x) {
    case 1:
        switch (val) {
            case 1:
                console.log('inner 1')
                break
            case 2:
                console.log('inner 2')
                break
        }
        break
    case 2:
        console.log('outer 2')
        break
}

// ✅ 测试11：字符串case
let str = 'hello'
switch (str) {
    case 'hello':
        console.log('greeting')
        break
    case 'bye':
        console.log('farewell')
        break
    default:
        console.log('unknown')
        break
}

// ✅ 测试12：仅default
switch (x) {
    default:
        console.log('default only')
        break
}

// ✅ 测试13：无break的fall-through完整示例
switch (x) {
    case 1:
        console.log('start')
    case 2:
        console.log('mid')
    case 3:
        console.log('end')
        break
    default:
        console.log('default')
}

// ✅ 测试14：switch中的return
function switchReturn() {
    switch (x) {
        case 1:
            return 'one'
        case 2:
            return 'two'
        default:
            return 'other'
    }
}

// ✅ 测试15：复杂switch场景
let code = 'error'
switch (code) {
    case 'success':
        console.log('✓ Success')
        break
    case 'warning':
        console.log('⚠ Warning')
        break
    case 'error':
        console.log('✗ Error')
        for (let i = 0; i < 3; i++) {
            console.log(`  attempt ${i}`)
        }
        break
    default:
        try {
            console.log('Unknown code: ' + code)
        } catch (e) {
            console.log('Error handling error')
        }
}

/* Es2025Parser.ts: SwitchStatement: switch ( Expression ) CaseBlock */
